package site.jlopen.secret.model.node;

import org.hibernate.validator.constraints.Range;

import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;
import site.jlopen.secret.common.SecretBaseForm;

/**
 * @ClassName: SecretNodeCreateReq
 * @Description: 创建/修改节点信息参数
 * @author ChenJiaLu
 * @date 2024年10月10日 下午2:19:26
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class SecretNodeCreateReq extends SecretBaseForm {
	/**
	 * 调用接口创建节点返回的ID，调用修改接口才需要
	 */
	private String id;
	/**
	 * 平台类型→edge/center/autonomy
	 */
    @NotBlank(message = "平台类型不能为空")
	private String platform;
	/**
	 * 部署模式→0:MPC/1:TEE/2:ALL-IN-ONE
	 */
    @Range(min = 0, max = 2, message = "部署模式值不正确")
	private int mode;
	/**
	 * 集群方式→0:中心化/1:P2P
	 */
    @Range(min = 0, max = 1, message = "集群方式值不正确")
	private int group;
	/**
	 * 自定义标题
	 */
    @NotBlank(message = "标题不能为空")
	private String title;
	/**
	 * 节点编号（唯一的编号，必须跟部署的节点ID一致）
	 */
    @NotBlank(message = "节点编号不能为空")
	private String code;
	/**
	 * 中心化 x 中心化、中心化 x 点对点组网模式 Lite 节点必填；普通中心化模式，点对点模式不需要填写
	 */
	private String master;
	/**
	 * 协议类型→notls/tls/mtls
	 */
    @NotBlank(message = "协议类型不能为空")
	private String protocol;
	/**
	 * token→文件在：/home/kuscia/var/certs/token
	 */
	private byte[] token;
	/**
	 * CA证书→文件在：/home/kuscia/var/certs/ca.crt
	 */
	private byte[] caFile;
	/**
	 * cert证书→文件在：/home/kuscia/var/certs/kusciaapi-server.crt
	 */
	private byte[] certFile;
	/**
	 * key公钥→文件在：/home/kuscia/var/certs/kusciaapi-server.key
	 */
	private byte[] keyFile;
	/**
	 * 节点grpc通讯→http(s)://ip:-p格式(根据脚本install.sh -p参数)
	 */
    @NotBlank(message = "网关(-p)不能为空")
	private String gateway;
	/**
	 * 节点grpc通讯→ip:-g格式(根据脚本install.sh -g参数)
	 */
    @NotBlank(message = "grpc(-g)通讯不能为空")
	private String grpc;
	/**
	 * →网络通讯http(s)://ip:-k(根据脚本install.sh -k参数)
	 */
    @NotBlank(message = "网络通讯(-k)通讯不能为空")
	private String http;
	/**
	 * 节点通讯→http(s)://ip:-q格式(根据脚本install.sh -q参数)
	 */
    @NotBlank(message = "节点通讯(-q)通讯不能为空")
	private String net;

	/**
	 * <strong>非证书模式直接调用</strong>
	 * 
	 * @Title: notls
	 */
	public SecretNodeCreateReq notls(String platform, int mode, int group, String title, String code, String master,
			String gateway, String grpc, String http, String net) {
		this.platform = platform;
		this.mode = mode;
		this.group = group;
		this.title = title;
		this.code = code;
		this.master = master;
		this.protocol = "notls";
		this.gateway = gateway;
		this.grpc = grpc;
		this.http = http;
		this.net = net;
		return this;
	}

	/**
	 * <strong>证书模式调用notls之后继续调用该方法补全证书</strong>
	 * 
	 * @Title: notls
	 */
	public SecretNodeCreateReq tls(byte[] token, byte[] caFile, byte[] certFile, byte[] keyFile) {
		this.protocol = "tls";
		this.token = token;
		this.caFile = caFile;
		this.certFile = certFile;
		this.keyFile = keyFile;
		return this;

	}

	/**
	 * <strong>证书模式调用notls之后继续调用该方法补全证书</strong>
	 * 
	 * @Title: notls
	 */
	public SecretNodeCreateReq mtls(byte[] token, byte[] caFile, byte[] certFile, byte[] keyFile) {
		this.protocol = "mtls";
		this.token = token;
		this.caFile = caFile;
		this.certFile = certFile;
		this.keyFile = keyFile;
		return this;
	}

}
